<template>
  <div class="eamilBox">
    <form action="javascript:;" method="get">
      <div class="eamil">{{$t('userAdmin.info.email.name')}}</div>
      <div class="eamilVal">
        <input type="text"
               autocomplete="off"
               id="content-e"
               :placeholder="$t('userAdmin.info.email.placeholder')"
               v-model="userEmail">
      </div>
      <div class="tips" style="height: 20px;" id="tips-e">{{$t('userAdmin.info.email.tip')}}</div>
      <div class="eamilSubmit"><input type="submit" :value="$t('userAdmin.info.email.submit')" id="submit-e" @click="onclickSubOfE()"></div>
      <div class="eamilReset"><input type="reset" :value="$t('userAdmin.info.email.reset')" id="reset-e" @click="onclickReOfE()"></div>

    </form>
  </div>
</template>

<script>
    export default {
        name: "UserAdminInfo-email",
        data(){
            return{
                userEmail:'',
                baseURL:'http://localhost:8081/user/update/email/'
            }
        },
        methods:{
            onclickSubOfE() {
                let regular = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
                if(!regular.test(this.userEmail)){
                    document.getElementById("tips-e").style.display="block"
                    document.getElementById("content-e").style.border = "1px solid rgb(250, 37, 0)"
                }else{
                    document.getElementById("tips-e").style.display="none"
                    document.getElementById("content-e").style.border = "1px solid rgb(216, 216, 216)"
                    this.axios.post(this.baseURL+this.userEmail).then((res)=>{
                        if (res.data==true){
                            this.successOpt(this.$t('userAdmin.info.email.optSuccess'))
                        } else {
                            this.failOpt(this.$t('userAdmin.info.email.optFail'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )

                }
            },
            onclickReOfE() {
                document.getElementById("tips-e").style.display="none"
                document.getElementById("content-e").style.border = "1px solid rgb(216, 216, 216)"
            },

            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            }
        }
    }

</script>

<style scoped>
  .eamilBox{
    margin: 10px auto;
    width: 930px;
    height: 80px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid rgb(226, 226, 226);
    border-radius: 3px;
    position: relative;
    letter-spacing: 1px;
  }
  .eamilBox form div{
    float: left;
    height: 35px;
    margin-top: 20px;
  }
  .eamil{
    width: 50px;
    margin-left: 25px;
    text-align: center;
    line-height: 35px;
    font-size: 15px;
    color: rgb(80, 80, 80);
  }
  .eamilVal{
    width: 400px;
    margin-left: 50px;
  }
  .eamilVal input{
    width: 440px;
    height: 31px;
    border: 1px solid rgb(216, 216, 216);
    background-color: transparent;
    color: rgb(105, 105, 105);
    border-radius: 3px;
    padding-left: 15px;
    transition: 0.3s;
  }
  .eamilSubmit{
    width: 120px;
    margin-left: 100px;
  }
  .eamilSubmit input{
    width: 120px;
    height: 35px;
    border: 1px solid rgb(138, 138, 138);
    color: rgb(241, 241, 241);
    border-radius: 3px;
    background-color: cadetblue;
  }
  .eamilSubmit input:hover{
    background-color: #00988a;
    color: rgb(255, 255, 255);
  }
  .eamilSubmit input:active{
    background-color: #047c70;
  }
  .eamilReset{
    width: 120px;
    margin-left: 20px;
  }
  .eamilReset input{
    width: 120px;
    height: 35px;
    border: 1px solid rgb(216, 216, 216);
    color: rgb(104, 104, 104);
    border-radius: 3px;
    background-color: white;
  }
  .eamilReset input:hover{
    background-color: rgb(215, 236, 236);
    color: rgb(73, 157, 160);
    border: 1px solid rgb(73, 157, 160);
  }
  .eamilReset input:active{
    border: 1px solid rgb(0, 0, 0);
  }
  .tips{
    width: 500px;
    font-size: 12px;
    color: rgb(255, 60, 25);
    position: absolute;
    top: 40px;
    left: 124px;
    display: none;
    transition: 0.3s;
  }
</style>
